package com.ftg.learn.controller;

import com.ftg.learn.service.SysUserService;
import com.ftg.learn.util.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 布衣
 */
@RestController
public class LoginController {

    @Resource
    SysUserService sysUserService;

    @PostMapping("/login")
    public R<String> login(@RequestParam("account") String account, @RequestParam("password") String password) {
        return sysUserService.login(account, password);
    }


    @PostMapping("/register")
    public R<Integer> register(@RequestParam("account") String account, @RequestParam("password") String password) {
        return sysUserService.register(account, password);
    }

    /**
     * 为用户分配角色
     */
    @PostMapping("/assignRole")
    public R<Boolean> assignRole(@RequestParam("userId") Integer userId, @RequestParam("roleId") List<Integer> roleIds) {
        return sysUserService.assignRole(userId,roleIds);
    }

}
